import re
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel, Field, validator, EmailStr, IPvAnyAddress

from enum import Enum


class DelBaseModel(BaseModel):
    uuid: int = Field(..., description="数据的uuid")


class PostTagDepartment(BaseModel):
    tag_key: str = Field(..., description="标签key值")
    tag_value: str = Field(..., description="标签value值")
    environment: str = Field(..., description="所属环境")
    maintain_department: str = Field(..., description="资产管理部门")
    belong_department: dict = Field(..., description="资产所属部门,按百分比说明。例如:运维60%, 数据库40%,则为:{'运维':60, '数据库':40}")
    job_number: str = Field(..., description="关联工单号")
    applicant: str = Field(..., description="资源申请人")
    owner: str = Field(..., description="资源归属人")
    expire_time: datetime = Field(..., description="过期时间")
    comment: Optional[str] = Field("", description="标签说明")


class PutTagDepartment(PostTagDepartment):
    uuid: int = Field(..., description="账单部门数据uuid")

class BillInstanceGroupBy(str, Enum):
    product_name = 'product_name'
    # company = 'company'
    #bill_class = "bill_class"
    environment = "environment"
    maintain_department = "maintain_department"
    belong_department = "belong_department"


class BillInstanceClassCluster(str, Enum):
    k8s = 'k8s-cluster'
    database = 'db-cluster'
    bigdata_realtime = "bigdata-realtime-cluster"
    bigdata_offline = "bigdata-offline-cluster"

class BillInstanceEnvironment(str, Enum):
    dev = 'development'
    prod = 'production'



class BillAnalysisGroupBy(str, Enum):
    # company = 'company'
    #bill_class = "bill_class"
    product_name = 'product_name'
    environment = "environment"
    maintain_department = "maintain_department"
    belong_department = "belong_department"

class PostBillMonth(BaseModel):
    bill_cycle: str = Field(..., description="账期月份")
    cloud_platform: str = Field(..., description="账单类型:阿里云/华为云/短信费用/签章费用")
    budget_amount: float = Field(..., description="预算金额")
    comment: str = Field("", description="月度账单的说明")

class PutBillMonth(BaseModel):
    budget_amount: float = Field(..., description="预算金额")
    cloud_platform: str = Field(..., description="账单类型:阿里云/华为云/短信费用/签章费用")
    comment: str = Field("", description="月度账单的说明")
    uuid: int = Field(..., description="月度账单uuid")

class PostInstanceTask(BaseModel):
    bill_cycle: str = Field(..., description="账期月份")
    
    
class CloudPlatform(str, Enum):
    type1 = '阿里云'
    type2 = '华为云'
    
    
class EventType(str, Enum):
    type1 = '自定义事件'
    type2 = '工单事件'
    
    
class InfoType(str, Enum):
    type1 = '实例id'
    type2 = '实例名称'
    type3 = '产品名称'
    type4 = 'appname标签值'
    
class PostBillEvent(BaseModel):
    name: str = Field(..., description="资产事件的名称")
    bill_cycle: str = Field(..., description="账期月份")
    cloud_platform: CloudPlatform = Field(CloudPlatform.type1, description="云平台")
    event_type: EventType = Field(EventType.type1, description="事件类别")
    relation_id: str = Field(..., description="关联事件id")
    info_type: InfoType = Field(InfoType.type1, description="信息类别")
    info_items: List[str] = Field(..., description="信息条目")
    comment: str = Field(..., description="事件说明")
    
    
    
class PutBillEvent(PostBillEvent):
    uuid: int = Field(..., description="资产事件uuid")
    
    
class PostBillEventWorkOrderTask(BaseModel):
    bill_cycle: str = Field(..., description="账期月份")